import { spiralPoints, ringPoints, rayPoints } from '../algorithm/polarMatrix.js'
import { _path } from './path.js'
import { _props } from "./canvas.js";
import { plainMatrix } from '../math/index.js'
import { _transform } from '../math/transform.js'
import { _mirrorPoints } from '../algorithm/mirror.js'
import { _polygon } from './polygon.js'
import { _mirrorColor } from '../common/index.js'


export const polarShape = (ctx, options, props) => {
    _polygon(ctx, options, props)
}

export const spiralShape = (ctx, options, props) => {
    let { transform, mirror } = options
    let matrix = spiralPoints(options).map(t => _transform(t, transform))
    matrix = _mirrorPoints(matrix, mirror)
    let points = plainMatrix(matrix)


    ctx.save();
    _props(ctx, props)
    _path(ctx, {
        ...options,
        points,
        mirror: null,
        color: mirror ? mirror.color : null
    }, props)
    ctx.restore();

}

export const ringShape = (ctx, options, props) => {
    let { transform, mirror } = options
    let matrix = ringPoints(options).map(t => _transform(t, transform))
    matrix = _mirrorPoints(matrix, mirror)
    let color = _mirrorColor(mirror)

    ctx.save();
    // _props(ctx, props)
    _path(ctx, {
        ...options,
        points: matrix,
        mirror: null,
        color //: mirror ? mirror.color : null
    }, props)
    ctx.restore();
}

export const rayShape = (ctx, options, props) => {
    let { transform, mirror } = options
    let matrix = rayPoints(options).map(t => _transform(t, transform))
    matrix = _mirrorPoints(matrix, mirror)

    ctx.save();
    _props(ctx, props)
    _path(ctx, {
        ...options,
        points: matrix,
        mirror: null,
        color: mirror ? mirror.color : null
    }, props)
    ctx.restore();
}